<?$page_title="Login Authentication";?>
<? include("includes/header.php") ?>

<?

if($_POST){
$username=strtoupper($_REQUEST["txtLoginId"]);
$password=$_REQUEST["txtLoginPwd"];
$username=addslashes($username); 
$password=addslashes($password); 

$reg_mode=$_REQUEST["mode"];
$validuser=0;
$result=validateUser($username,$password);

$retFlag=$result["retFlag"];


if($retFlag==1){
	$validuser=1;
	$userId=$result["userId"];

	$member_name=$result["member_name"];
	$memInfo=getMemberInfo($userId);
	$_SESSION["member_id"]=$userId;
	$_SESSION["member_name"]=$member_name;
	$_SESSION["is_bk"]=$memInfo["are_you_bk"];
	

	header("Location: profile.php");
}

$error_msg=Array("Invalid Membership ID. Please Check.","","Invalid Password. Please try again.");
}
?>

<form method="post" action="login.php?mode=<?=$_GET["mode"]?>" name="frmLogin" onsubmit="return validateForm(this)" >


<?if($validuser==0 && $_POST){?>
<br/>
<div class="errorBox" style="margin-left:80px"><?=$error_msg[$retFlag]?></div>
<? }else{ ?>
<br/>
<? } ?>

<div class="loginBox">
	<div class="fleft" style="width:110px;padding-top:20px;padding-right:15px;">
	<img src="images/key.jpg" >
	<p style="padding-left:4px">
	<a style="font-size:9px;margin:0px;padding:0px" href="forgotpwd.php?mode=1">Forgot your member Id?</a>
	<a style="font-size:9px;margin:0px;padding:0px" href="forgotpwd.php?mode=0">Forgot your password?</a>
	</p>
	
	</div>
	<div class="fnone">
		<table border="0"   width="300"  >
			<tr>
				<td  width="40%" >Membership ID :  <span class="note" style="padding-left:80px">(e.g BKITCXXXXX)</span>
				<br/><input type="text" size="35" name="txtLoginId" class="txtbox captial" maxlength="12"/></td>
			</tr>
			<tr>
				<td  width="40%" ><span class="label">Password :</span><br/> <input type="password" size="35" name="txtLoginPwd" class="txtbox"/></td>
			</tr>
		
			<tr>
				<td colspan="2" align="right">

					<input type="submit" value="Sign in" class="button" style="margin-right:1px"/>
					<input type="button" value="Cancel" class="button" onclick="javascript:history.back()"/>
					<input type="hidden" name="hmode" value="<?=$_GET["mode"]?>"/><br/>
					
				</td>
			</tr>

		</table>
	</div>

</div>

</form>
<script type="text/javascript">
function validateForm(vForm){

var msg="Please correct the errors:\n\n";
var eMode=0;

if(vForm.txtLoginId.value==""){
eMode=1;
msg +=" Membership ID field cannot be empty.\n\n";
}
if(vForm.txtLoginPwd.value==""){
	eMode=1;
	msg +=" Password field cannot be empty.\n\n";
}

if(eMode==1){
alert(msg);
return false;
}

}

</script>


<? include("includes/footer.php") ?>